{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Final Solution.ipynb",
      "version": "0.3.2",
      "provenance": []
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.5"
    },
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    }
  },
  "cells": [
    {
      "metadata": {
        "id": "BvNJjIGeuEW_",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Predict The Flight Ticket Price Hackathon"
      ]
    },
    {
      "metadata": {
        "id": "E8Yt7GofuEXB",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "**Features**:\n",
        "\n",
        "    Airline: The name of the airline.\n",
        "    Date_of_Journey: The date of the journey\n",
        "    Source: The source from which the service begins.\n",
        "    Destination: The destination where the service ends.\n",
        "    Route: The route taken by the flight to reach the destination.\n",
        "    Dep_Time: The time when the journey starts from the source.\n",
        "    Arrival_Time: Time of arrival at the destination.\n",
        "    Duration: Total duration of the flight.\n",
        "    Total_Stops: Total stops between the source and destination.\n",
        "    Additional_Info: Additional information about the flight\n",
        "    Price: The price of the ticket"
      ]
    },
    {
      "metadata": {
        "id": "RJkrc8nEuEXD",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "### Import data and libraries"
      ]
    },
    {
      "metadata": {
        "id": "yKoxbDqtuEXD",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import warnings\n",
        "warnings.filterwarnings('ignore')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "6S4QzBH-uEXI",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train = pd.read_excel('Data_Train.xlsx')\n",
        "test = pd.read_excel('Test_set.xlsx')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "xhWn1-5vuEXL",
        "colab_type": "code",
        "colab": {},
        "outputId": "f81ff1ee-416a-4ca7-deec-700e1b3e7b91"
      },
      "cell_type": "code",
      "source": [
        "train.shape, test.shape"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "((10683, 11), (2671, 10))"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 165
        }
      ]
    },
    {
      "metadata": {
        "id": "LiQVOHqcuEXS",
        "colab_type": "code",
        "colab": {},
        "outputId": "e571b4a3-e232-4f76-a830-e615a8664f3a"
      },
      "cell_type": "code",
      "source": [
        "train.info()\n",
        "#test.info()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 10683 entries, 0 to 10682\n",
            "Data columns (total 11 columns):\n",
            "Airline            10683 non-null object\n",
            "Date_of_Journey    10683 non-null object\n",
            "Source             10683 non-null object\n",
            "Destination        10683 non-null object\n",
            "Route              10682 non-null object\n",
            "Dep_Time           10683 non-null object\n",
            "Arrival_Time       10683 non-null object\n",
            "Duration           10683 non-null object\n",
            "Total_Stops        10682 non-null object\n",
            "Additional_Info    10683 non-null object\n",
            "Price              10683 non-null int64\n",
            "dtypes: int64(1), object(10)\n",
            "memory usage: 918.1+ KB\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "76SAm2JIuEXW",
        "colab_type": "code",
        "colab": {},
        "outputId": "42e8a9f0-9c6a-43d3-80a6-b8b337ac3f34"
      },
      "cell_type": "code",
      "source": [
        "train.head(5)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Airline</th>\n",
              "      <th>Date_of_Journey</th>\n",
              "      <th>Source</th>\n",
              "      <th>Destination</th>\n",
              "      <th>Route</th>\n",
              "      <th>Dep_Time</th>\n",
              "      <th>Arrival_Time</th>\n",
              "      <th>Duration</th>\n",
              "      <th>Total_Stops</th>\n",
              "      <th>Additional_Info</th>\n",
              "      <th>Price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>IndiGo</td>\n",
              "      <td>24/03/2019</td>\n",
              "      <td>Banglore</td>\n",
              "      <td>New Delhi</td>\n",
              "      <td>BLR → DEL</td>\n",
              "      <td>22:20</td>\n",
              "      <td>01:10 22 Mar</td>\n",
              "      <td>2h 50m</td>\n",
              "      <td>non-stop</td>\n",
              "      <td>No info</td>\n",
              "      <td>3897</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Air India</td>\n",
              "      <td>1/05/2019</td>\n",
              "      <td>Kolkata</td>\n",
              "      <td>Banglore</td>\n",
              "      <td>CCU → IXR → BBI → BLR</td>\n",
              "      <td>05:50</td>\n",
              "      <td>13:15</td>\n",
              "      <td>7h 25m</td>\n",
              "      <td>2 stops</td>\n",
              "      <td>No info</td>\n",
              "      <td>7662</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Jet Airways</td>\n",
              "      <td>9/06/2019</td>\n",
              "      <td>Delhi</td>\n",
              "      <td>Cochin</td>\n",
              "      <td>DEL → LKO → BOM → COK</td>\n",
              "      <td>09:25</td>\n",
              "      <td>04:25 10 Jun</td>\n",
              "      <td>19h</td>\n",
              "      <td>2 stops</td>\n",
              "      <td>No info</td>\n",
              "      <td>13882</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>IndiGo</td>\n",
              "      <td>12/05/2019</td>\n",
              "      <td>Kolkata</td>\n",
              "      <td>Banglore</td>\n",
              "      <td>CCU → NAG → BLR</td>\n",
              "      <td>18:05</td>\n",
              "      <td>23:30</td>\n",
              "      <td>5h 25m</td>\n",
              "      <td>1 stop</td>\n",
              "      <td>No info</td>\n",
              "      <td>6218</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>IndiGo</td>\n",
              "      <td>01/03/2019</td>\n",
              "      <td>Banglore</td>\n",
              "      <td>New Delhi</td>\n",
              "      <td>BLR → NAG → DEL</td>\n",
              "      <td>16:50</td>\n",
              "      <td>21:35</td>\n",
              "      <td>4h 45m</td>\n",
              "      <td>1 stop</td>\n",
              "      <td>No info</td>\n",
              "      <td>13302</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "       Airline Date_of_Journey    Source Destination                  Route  \\\n",
              "0       IndiGo      24/03/2019  Banglore   New Delhi              BLR → DEL   \n",
              "1    Air India       1/05/2019   Kolkata    Banglore  CCU → IXR → BBI → BLR   \n",
              "2  Jet Airways       9/06/2019     Delhi      Cochin  DEL → LKO → BOM → COK   \n",
              "3       IndiGo      12/05/2019   Kolkata    Banglore        CCU → NAG → BLR   \n",
              "4       IndiGo      01/03/2019  Banglore   New Delhi        BLR → NAG → DEL   \n",
              "\n",
              "  Dep_Time  Arrival_Time Duration Total_Stops Additional_Info  Price  \n",
              "0    22:20  01:10 22 Mar   2h 50m    non-stop         No info   3897  \n",
              "1    05:50         13:15   7h 25m     2 stops         No info   7662  \n",
              "2    09:25  04:25 10 Jun      19h     2 stops         No info  13882  \n",
              "3    18:05         23:30   5h 25m      1 stop         No info   6218  \n",
              "4    16:50         21:35   4h 45m      1 stop         No info  13302  "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 167
        }
      ]
    },
    {
      "metadata": {
        "scrolled": true,
        "id": "mG9gZHiyuEXa",
        "colab_type": "code",
        "colab": {},
        "outputId": "f3ef6166-bd1a-4876-b202-9b502e9add53"
      },
      "cell_type": "code",
      "source": [
        "for i in train.columns:\n",
        "    print(\"Unique values in\", i, train[i].nunique())"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Unique values in Airline 12\n",
            "Unique values in Date_of_Journey 44\n",
            "Unique values in Source 5\n",
            "Unique values in Destination 6\n",
            "Unique values in Route 128\n",
            "Unique values in Dep_Time 222\n",
            "Unique values in Arrival_Time 1343\n",
            "Unique values in Duration 368\n",
            "Unique values in Total_Stops 5\n",
            "Unique values in Additional_Info 10\n",
            "Unique values in Price 1870\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "nDDU7EyguEXd",
        "colab_type": "code",
        "colab": {},
        "outputId": "c7dbce72-42bf-4e26-f520-352781b7e113"
      },
      "cell_type": "code",
      "source": [
        "for i in test.columns:\n",
        "    print(\"Unique values in\", i, test[i].nunique())"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Unique values in Airline 11\n",
            "Unique values in Date_of_Journey 44\n",
            "Unique values in Source 5\n",
            "Unique values in Destination 6\n",
            "Unique values in Route 100\n",
            "Unique values in Dep_Time 199\n",
            "Unique values in Arrival_Time 704\n",
            "Unique values in Duration 320\n",
            "Unique values in Total_Stops 5\n",
            "Unique values in Additional_Info 6\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "BhBUbLtZuEXh",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "### Data pre-processing"
      ]
    },
    {
      "metadata": {
        "id": "-GaLcYDhuEXi",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df = train[['Airline', 'Source', 'Destination', 'Total_Stops', 'Additional_Info', 'Date_of_Journey', 'Dep_Time', \n",
        "                  'Route', 'Arrival_Time', 'Price']]\n",
        "test_df = test[['Airline', 'Source', 'Destination', 'Total_Stops', 'Additional_Info', 'Date_of_Journey', 'Dep_Time', \n",
        "                'Route', 'Arrival_Time']]"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "aBdVfyZBuEXk",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "This is new feature __Booking_Class__ to identify the booking class i.e. **Economy, Premium Economy & Business**. For the __'Premium Economy'__ and __Business__ class its already mentioned. Rest of the airlines I have assumed as __Economy__."
      ]
    },
    {
      "metadata": {
        "id": "wCkV8-T-uEXm",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "Class = {'IndiGo': 'Economy',\n",
        "         'GoAir': 'Economy',\n",
        "         'Vistara': 'Economy',\n",
        "         'Vistara Premium economy': 'Premium Economy',\n",
        "         'Air Asia': 'Economy',\n",
        "         'Trujet': 'Economy',\n",
        "         'Jet Airways': 'Economy',\n",
        "         'SpiceJet': 'Economy',\n",
        "         'Jet Airways Business': 'Business',\n",
        "         'Air India': 'Economy',\n",
        "         'Multiple carriers': 'Economy',\n",
        "         'Multiple carriers Premium economy': 'Premium Economy'}\n",
        "train_df['Booking_Class'] = train_df['Airline'].map(Class)\n",
        "test_df['Booking_Class'] = test_df['Airline'].map(Class)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "bc-xFtzBuEXp",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "This is new feature is used to indicate __Market_Share__ of each airline. This information is taken mostly from Wikipedia. For _Multiple carriers_ & _Multiple carriers Premium Economy_ I have assumed 1% & for the _Trujet_ which is new entrant in the Airline I have assumed 0.1%."
      ]
    },
    {
      "metadata": {
        "id": "Jq4W0xK-uEXq",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "market = {'IndiGo': 41.3,\n",
        "         'GoAir': 8.4,\n",
        "         'Vistara': 3.3,\n",
        "         'Vistara Premium economy': 3.3,\n",
        "         'Air Asia': 3.3,\n",
        "         'Trujet': 0.1,\n",
        "         'Jet Airways': 17.8,\n",
        "         'SpiceJet': 13.3,\n",
        "         'Jet Airways Business': 17.8,\n",
        "         'Air India': 13.5,\n",
        "         'Multiple carriers': 1,\n",
        "         'Multiple carriers Premium economy': 1}\n",
        "train_df['Market_Share'] = train_df['Airline'].map(market)\n",
        "test_df['Market_Share'] = test_df['Airline'].map(market)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "Ik5l1GsMuEXt",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "One of the very important factors which influences Flight Ticket price is how soon you book the ticket. Since this information was not provided in the dataset I have assumed 01-Mar-2019 as ticket booking date and created new feature __Days_to_Departure__ "
      ]
    },
    {
      "metadata": {
        "id": "PBSKulSfuEXu",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "df1 = train_df.copy() \n",
        "df1['Day_of_Booking'] = '1/3/2019'\n",
        "df1['Day_of_Booking'] = pd.to_datetime(df1['Day_of_Booking'],format='%d/%m/%Y')\n",
        "df1['Date_of_Journey'] = pd.to_datetime(df1['Date_of_Journey'],format='%d/%m/%Y')\n",
        "df1['Days_to_Departure'] = (df1['Date_of_Journey'] - df1['Day_of_Booking']).dt.days\n",
        "train_df['Days_to_Departure'] = df1['Days_to_Departure']\n",
        "\n",
        "df2 = test_df.copy() \n",
        "df2['Day_of_Booking'] = '1/3/2019'\n",
        "df2['Day_of_Booking'] = pd.to_datetime(df2['Day_of_Booking'],format='%d/%m/%Y')\n",
        "df2['Date_of_Journey'] = pd.to_datetime(df2['Date_of_Journey'],format='%d/%m/%Y')\n",
        "df2['Days_to_Departure'] = (df2['Date_of_Journey'] - df2['Day_of_Booking']).dt.days\n",
        "test_df['Days_to_Departure'] = df2['Days_to_Departure']\n",
        "\n",
        "del df1, df2"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "2fnHTryVuEXx",
        "colab_type": "code",
        "colab": {},
        "outputId": "74088091-1859-4617-8170-1d89ffe1a950"
      },
      "cell_type": "code",
      "source": [
        "train_df.head(2)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Airline</th>\n",
              "      <th>Source</th>\n",
              "      <th>Destination</th>\n",
              "      <th>Total_Stops</th>\n",
              "      <th>Additional_Info</th>\n",
              "      <th>Date_of_Journey</th>\n",
              "      <th>Dep_Time</th>\n",
              "      <th>Route</th>\n",
              "      <th>Arrival_Time</th>\n",
              "      <th>Price</th>\n",
              "      <th>Booking_Class</th>\n",
              "      <th>Market_Share</th>\n",
              "      <th>Days_to_Departure</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>IndiGo</td>\n",
              "      <td>Banglore</td>\n",
              "      <td>New Delhi</td>\n",
              "      <td>non-stop</td>\n",
              "      <td>No info</td>\n",
              "      <td>24/03/2019</td>\n",
              "      <td>22:20</td>\n",
              "      <td>BLR → DEL</td>\n",
              "      <td>01:10 22 Mar</td>\n",
              "      <td>3897</td>\n",
              "      <td>Economy</td>\n",
              "      <td>41.3</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Air India</td>\n",
              "      <td>Kolkata</td>\n",
              "      <td>Banglore</td>\n",
              "      <td>2 stops</td>\n",
              "      <td>No info</td>\n",
              "      <td>1/05/2019</td>\n",
              "      <td>05:50</td>\n",
              "      <td>CCU → IXR → BBI → BLR</td>\n",
              "      <td>13:15</td>\n",
              "      <td>7662</td>\n",
              "      <td>Economy</td>\n",
              "      <td>13.5</td>\n",
              "      <td>61</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     Airline    Source Destination Total_Stops Additional_Info  \\\n",
              "0     IndiGo  Banglore   New Delhi    non-stop         No info   \n",
              "1  Air India   Kolkata    Banglore     2 stops         No info   \n",
              "\n",
              "  Date_of_Journey Dep_Time                  Route  Arrival_Time  Price  \\\n",
              "0      24/03/2019    22:20              BLR → DEL  01:10 22 Mar   3897   \n",
              "1       1/05/2019    05:50  CCU → IXR → BBI → BLR         13:15   7662   \n",
              "\n",
              "  Booking_Class  Market_Share  Days_to_Departure  \n",
              "0       Economy          41.3                 23  \n",
              "1       Economy          13.5                 61  "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 174
        }
      ]
    },
    {
      "metadata": {
        "id": "KBNqTSzMuEX4",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# Let's take only Arrial Time (withut including date)\n",
        "train_df['Arrival_Time'] = train['Arrival_Time'].str.split(' ').str[0]\n",
        "test_df['Arrival_Time'] = test['Arrival_Time'].str.split(' ').str[0]"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "XyA5UTe7uEX7",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Another important parameter which influences Flight Price is Departure time of the flight i.e. Morning, Noon, Evening or Night. So created this new feature __Dep_timeofday__ which indicate Departure Time of the day. Also applied same concept to Arrival Time and created another feature __Arr_timeofday__"
      ]
    },
    {
      "metadata": {
        "id": "eVvswKE3uEX8",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "def get_departure(dep):\n",
        "    dep = dep.split(':')\n",
        "    dep = int(dep[0])\n",
        "    if (dep >= 6 and dep < 12):\n",
        "        return 'Morning'\n",
        "    elif (dep >= 12 and dep < 17):\n",
        "        return 'Noon'\n",
        "    elif (dep >= 17 and dep < 20):\n",
        "        return 'Evening'\n",
        "    else:\n",
        "        return 'Night'\n",
        "    \n",
        "train_df['Dep_timeofday'] = train['Dep_Time'].apply(get_departure)   \n",
        "test_df['Dep_timeofday'] = test['Dep_Time'].apply(get_departure) \n",
        "\n",
        "train_df['Arr_timeofday'] = train['Arrival_Time'].apply(get_departure)   \n",
        "test_df['Arr_timeofday'] = test['Arrival_Time'].apply(get_departure) "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "feHr-tHauEYB",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Converted __Total_Stops__ categorical column into numeric"
      ]
    },
    {
      "metadata": {
        "id": "LdlMNFcHuEYC",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df['Total_Stops'] = train_df['Total_Stops'].str.replace('non-stop','0')\n",
        "train_df['Total_Stops'] = train_df['Total_Stops'].str.replace('stops','')\n",
        "train_df['Total_Stops'] = train_df['Total_Stops'].str.replace('stop','')\n",
        "train_df['Total_Stops'].fillna(0, inplace=True)   \n",
        "train_df['Total_Stops'] = train_df['Total_Stops'].astype(float)\n",
        "\n",
        "test_df['Total_Stops'] = test_df['Total_Stops'].str.replace('non-stop','0')\n",
        "test_df['Total_Stops'] = test_df['Total_Stops'].str.replace('stops','')\n",
        "test_df['Total_Stops'] = test_df['Total_Stops'].str.replace('stop','')\n",
        "#test_df['Total_Stops'].fillna(0, inplace=True)\n",
        "test_df['Total_Stops'] = test_df['Total_Stops'].astype(float)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "3XdsMzDjuEYH",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Converted __Duration__ column into minutes"
      ]
    },
    {
      "metadata": {
        "id": "d6eymKUiuEYK",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df['Hours'] = train['Duration'].str.split(' ').str[0]\n",
        "train_df['Hours'] = train_df['Hours'].str.replace('h','').astype(float)\n",
        "train_df['Hours'].fillna(0, inplace=True) \n",
        "\n",
        "train_df['Minutes'] = train['Duration'].str.split(' ').str[1]\n",
        "train_df['Minutes'] = train_df['Minutes'].str.replace('m','').astype(float)\n",
        "train_df['Minutes'].fillna(0, inplace=True)\n",
        "\n",
        "test_df['Hours'] = test['Duration'].str.split(' ').str[0]\n",
        "test_df['Hours'] = test_df['Hours'].str.replace('h','').astype(float)\n",
        "test_df['Hours'].fillna(0, inplace=True) \n",
        "\n",
        "test_df['Minutes'] = test['Duration'].str.split(' ').str[1]\n",
        "test_df['Minutes'] = test_df['Minutes'].str.replace('m','').astype(float)\n",
        "test_df['Minutes'].fillna(0, inplace=True)\n",
        "\n",
        "train_df['Hours'] = train_df['Hours'] * 60\n",
        "train_df['Duration'] = train_df['Hours'] + train_df['Minutes']\n",
        "\n",
        "test_df['Hours'] = test_df['Hours'] * 60\n",
        "test_df['Duration'] = test_df['Hours'] + test_df['Minutes']\n",
        "\n",
        "train_df.drop(['Hours', 'Minutes'], axis=1, inplace=True)\n",
        "test_df.drop(['Hours', 'Minutes'], axis=1, inplace=True)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "SODSQk9QuEYY",
        "colab_type": "code",
        "colab": {},
        "outputId": "f1ea085d-5c1f-4b46-a75e-36b324e64399"
      },
      "cell_type": "code",
      "source": [
        "train_df.head(2)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Airline</th>\n",
              "      <th>Source</th>\n",
              "      <th>Destination</th>\n",
              "      <th>Total_Stops</th>\n",
              "      <th>Additional_Info</th>\n",
              "      <th>Date_of_Journey</th>\n",
              "      <th>Dep_Time</th>\n",
              "      <th>Route</th>\n",
              "      <th>Arrival_Time</th>\n",
              "      <th>Price</th>\n",
              "      <th>Booking_Class</th>\n",
              "      <th>Market_Share</th>\n",
              "      <th>Days_to_Departure</th>\n",
              "      <th>Dep_timeofday</th>\n",
              "      <th>Arr_timeofday</th>\n",
              "      <th>Duration</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>IndiGo</td>\n",
              "      <td>Banglore</td>\n",
              "      <td>New Delhi</td>\n",
              "      <td>0.0</td>\n",
              "      <td>No info</td>\n",
              "      <td>24/03/2019</td>\n",
              "      <td>22:20</td>\n",
              "      <td>BLR → DEL</td>\n",
              "      <td>01:10</td>\n",
              "      <td>3897</td>\n",
              "      <td>Economy</td>\n",
              "      <td>41.3</td>\n",
              "      <td>23</td>\n",
              "      <td>Night</td>\n",
              "      <td>Night</td>\n",
              "      <td>170.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Air India</td>\n",
              "      <td>Kolkata</td>\n",
              "      <td>Banglore</td>\n",
              "      <td>2.0</td>\n",
              "      <td>No info</td>\n",
              "      <td>1/05/2019</td>\n",
              "      <td>05:50</td>\n",
              "      <td>CCU → IXR → BBI → BLR</td>\n",
              "      <td>13:15</td>\n",
              "      <td>7662</td>\n",
              "      <td>Economy</td>\n",
              "      <td>13.5</td>\n",
              "      <td>61</td>\n",
              "      <td>Night</td>\n",
              "      <td>Noon</td>\n",
              "      <td>445.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     Airline    Source Destination  Total_Stops Additional_Info  \\\n",
              "0     IndiGo  Banglore   New Delhi          0.0         No info   \n",
              "1  Air India   Kolkata    Banglore          2.0         No info   \n",
              "\n",
              "  Date_of_Journey Dep_Time                  Route Arrival_Time  Price  \\\n",
              "0      24/03/2019    22:20              BLR → DEL        01:10   3897   \n",
              "1       1/05/2019    05:50  CCU → IXR → BBI → BLR        13:15   7662   \n",
              "\n",
              "  Booking_Class  Market_Share  Days_to_Departure Dep_timeofday Arr_timeofday  \\\n",
              "0       Economy          41.3                 23         Night         Night   \n",
              "1       Economy          13.5                 61         Night          Noon   \n",
              "\n",
              "   Duration  \n",
              "0     170.0  \n",
              "1     445.0  "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 179
        }
      ]
    },
    {
      "metadata": {
        "id": "jnJvXqCsuEYc",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Let's take logarithmic values of __Price__ and __Duration__"
      ]
    },
    {
      "metadata": {
        "id": "TXYqnezLuEYe",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df['Price'] = np.log1p(train_df['Price'])\n",
        "\n",
        "train_df['Duration'] = np.log1p(train_df['Duration'])\n",
        "test_df['Duration'] = np.log1p(test_df['Duration'])"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "fWWU_fEauEYg",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df['Additional_Info'] = train_df['Additional_Info'].str.replace('No info', 'No Info')\n",
        "test_df['Additional_Info'] = test_df['Additional_Info'].str.replace('No info', 'No Info')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "3iK0DyLpuEYi",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Therea are lot of categorical variable. Used pandas __get_dummies__ to deal with all the categorical variables"
      ]
    },
    {
      "metadata": {
        "id": "F6uSLuBxuEYi",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df = pd.get_dummies(train_df, columns=['Airline', 'Source', 'Destination', 'Additional_Info', 'Date_of_Journey',\n",
        "                                             'Dep_Time', 'Arrival_Time', 'Dep_timeofday', 'Booking_Class', 'Arr_timeofday'],\n",
        "                          drop_first=True)\n",
        "test_df = pd.get_dummies(test_df, columns=['Airline', 'Source', 'Destination', 'Additional_Info', 'Date_of_Journey',\n",
        "                                           'Dep_Time', 'Arrival_Time', 'Dep_timeofday', 'Booking_Class', 'Arr_timeofday'],\n",
        "                         drop_first=True)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "QyKXO9jGuEYl",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "For the __Route__ column, I have applied TF-IDF text extraction to create one column for each value of location. There are 43 unique location so 43 new feature created out of __Route__ column. The results are stored in dataframe."
      ]
    },
    {
      "metadata": {
        "id": "t5SCqF7DuEYl",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "def clean_route(route):\n",
        "    route = str(route)\n",
        "    route = route.split(' → ')\n",
        "    return ' '.join(route)\n",
        "\n",
        "train_df['Route'] = train_df['Route'].apply(clean_route)\n",
        "test_df['Route'] = test_df['Route'].apply(clean_route)\n",
        "\n",
        "from sklearn.feature_extraction.text import TfidfVectorizer\n",
        "tf = TfidfVectorizer(ngram_range=(1, 1), lowercase=False)\n",
        "train_route = tf.fit_transform(train_df['Route'])\n",
        "test_route = tf.transform(test_df['Route'])\n",
        "\n",
        "train_route = pd.DataFrame(data=train_route.toarray(), columns=tf.get_feature_names())\n",
        "test_route = pd.DataFrame(data=test_route.toarray(), columns=tf.get_feature_names())"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "qpS31ZrXuEYp",
        "colab_type": "code",
        "colab": {},
        "outputId": "052f6689-e787-4f26-dfa2-cb3699e493d0"
      },
      "cell_type": "code",
      "source": [
        "train_route.head(5)\n",
        "#test_route.head(5)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>AMD</th>\n",
              "      <th>ATQ</th>\n",
              "      <th>BBI</th>\n",
              "      <th>BDQ</th>\n",
              "      <th>BHO</th>\n",
              "      <th>BLR</th>\n",
              "      <th>BOM</th>\n",
              "      <th>CCU</th>\n",
              "      <th>COK</th>\n",
              "      <th>DED</th>\n",
              "      <th>...</th>\n",
              "      <th>PAT</th>\n",
              "      <th>PNQ</th>\n",
              "      <th>RPR</th>\n",
              "      <th>STV</th>\n",
              "      <th>TRV</th>\n",
              "      <th>UDR</th>\n",
              "      <th>VGA</th>\n",
              "      <th>VNS</th>\n",
              "      <th>VTZ</th>\n",
              "      <th>nan</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.783012</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.619874</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.194833</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.248235</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.241494</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.271844</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.274089</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.349214</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.284914</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 43 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "   AMD  ATQ       BBI  BDQ  BHO       BLR       BOM       CCU       COK  DED  \\\n",
              "0  0.0  0.0  0.000000  0.0  0.0  0.783012  0.000000  0.000000  0.000000  0.0   \n",
              "1  0.0  0.0  0.619874  0.0  0.0  0.194833  0.000000  0.248235  0.000000  0.0   \n",
              "2  0.0  0.0  0.000000  0.0  0.0  0.000000  0.241494  0.000000  0.271844  0.0   \n",
              "3  0.0  0.0  0.000000  0.0  0.0  0.274089  0.000000  0.349214  0.000000  0.0   \n",
              "4  0.0  0.0  0.000000  0.0  0.0  0.284914  0.000000  0.000000  0.000000  0.0   \n",
              "\n",
              "  ...   PAT  PNQ  RPR  STV  TRV  UDR  VGA  VNS  VTZ  nan  \n",
              "0 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  \n",
              "1 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  \n",
              "2 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  \n",
              "3 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  \n",
              "4 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  \n",
              "\n",
              "[5 rows x 43 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 184
        }
      ]
    },
    {
      "metadata": {
        "id": "iVJdDcbJuEYt",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Now, let's concatenate __train_route__ and __test_route__ dataframes with corresponding __train_df__ and __test_df__ dataframe which will be used further for modelling "
      ]
    },
    {
      "metadata": {
        "id": "d-UYEH8JuEYu",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df = pd.concat([train_df, train_route], axis=1) \n",
        "train_df.drop('Route', axis=1, inplace=True)\n",
        "\n",
        "test_df = pd.concat([test_df, test_route], axis=1) \n",
        "test_df.drop('Route', axis=1, inplace=True)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "1agQagzTuEYw",
        "colab_type": "code",
        "colab": {},
        "outputId": "aac42b53-b8f4-42b3-da5f-9c4fc48f67f4"
      },
      "cell_type": "code",
      "source": [
        "train_df.head()\n",
        "#test_df.head()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Total_Stops</th>\n",
              "      <th>Price</th>\n",
              "      <th>Market_Share</th>\n",
              "      <th>Days_to_Departure</th>\n",
              "      <th>Duration</th>\n",
              "      <th>Airline_Air India</th>\n",
              "      <th>Airline_GoAir</th>\n",
              "      <th>Airline_IndiGo</th>\n",
              "      <th>Airline_Jet Airways</th>\n",
              "      <th>Airline_Jet Airways Business</th>\n",
              "      <th>...</th>\n",
              "      <th>PAT</th>\n",
              "      <th>PNQ</th>\n",
              "      <th>RPR</th>\n",
              "      <th>STV</th>\n",
              "      <th>TRV</th>\n",
              "      <th>UDR</th>\n",
              "      <th>VGA</th>\n",
              "      <th>VNS</th>\n",
              "      <th>VTZ</th>\n",
              "      <th>nan</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0.0</td>\n",
              "      <td>8.268219</td>\n",
              "      <td>41.3</td>\n",
              "      <td>23</td>\n",
              "      <td>5.141664</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2.0</td>\n",
              "      <td>8.944159</td>\n",
              "      <td>13.5</td>\n",
              "      <td>61</td>\n",
              "      <td>6.100319</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2.0</td>\n",
              "      <td>9.538420</td>\n",
              "      <td>17.8</td>\n",
              "      <td>100</td>\n",
              "      <td>7.039660</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1.0</td>\n",
              "      <td>8.735364</td>\n",
              "      <td>41.3</td>\n",
              "      <td>72</td>\n",
              "      <td>5.786897</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>1.0</td>\n",
              "      <td>9.495745</td>\n",
              "      <td>41.3</td>\n",
              "      <td>0</td>\n",
              "      <td>5.655992</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 570 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "   Total_Stops     Price  Market_Share  Days_to_Departure  Duration  \\\n",
              "0          0.0  8.268219          41.3                 23  5.141664   \n",
              "1          2.0  8.944159          13.5                 61  6.100319   \n",
              "2          2.0  9.538420          17.8                100  7.039660   \n",
              "3          1.0  8.735364          41.3                 72  5.786897   \n",
              "4          1.0  9.495745          41.3                  0  5.655992   \n",
              "\n",
              "   Airline_Air India  Airline_GoAir  Airline_IndiGo  Airline_Jet Airways  \\\n",
              "0                  0              0               1                    0   \n",
              "1                  1              0               0                    0   \n",
              "2                  0              0               0                    1   \n",
              "3                  0              0               1                    0   \n",
              "4                  0              0               1                    0   \n",
              "\n",
              "   Airline_Jet Airways Business ...   PAT  PNQ  RPR  STV  TRV  UDR  VGA  VNS  \\\n",
              "0                             0 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   \n",
              "1                             0 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   \n",
              "2                             0 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   \n",
              "3                             0 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   \n",
              "4                             0 ...   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   \n",
              "\n",
              "   VTZ  nan  \n",
              "0  0.0  0.0  \n",
              "1  0.0  0.0  \n",
              "2  0.0  0.0  \n",
              "3  0.0  0.0  \n",
              "4  0.0  0.0  \n",
              "\n",
              "[5 rows x 570 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 186
        }
      ]
    },
    {
      "metadata": {
        "id": "CIcCz27CuEY1",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "### Train test split"
      ]
    },
    {
      "metadata": {
        "id": "hNtOmOxxuEY2",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "X = train_df.drop(labels=['Price'], axis=1)\n",
        "y = train_df['Price'].values\n",
        "\n",
        "from sklearn.model_selection import train_test_split\n",
        "X_train, X_cv, y_train, y_cv = train_test_split(X, y, test_size=0.25, random_state=1)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "60yS9cwMuEY5",
        "colab_type": "code",
        "colab": {},
        "outputId": "d9be03dc-d087-4f9b-a2ad-f81a4fc39408"
      },
      "cell_type": "code",
      "source": [
        "X_train.shape, y_train.shape, X_cv.shape, y_cv.shape"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "((8012, 569), (8012,), (2671, 569), (2671,))"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 188
        }
      ]
    },
    {
      "metadata": {
        "id": "3mXeKFj9uEY9",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "### Build the model"
      ]
    },
    {
      "metadata": {
        "id": "kPSzdinjuEZA",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "from math import sqrt \n",
        "from sklearn.metrics import mean_squared_log_error"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "w3l0RIKwuEZC",
        "colab_type": "code",
        "colab": {},
        "outputId": "5acc06cf-7368-4dc6-928a-4e9f4ca2937b"
      },
      "cell_type": "code",
      "source": [
        "import lightgbm as lgb\n",
        "train_data = lgb.Dataset(X_train, label=y_train)\n",
        "test_data = lgb.Dataset(X_cv, label=y_cv)\n",
        "\n",
        "param = {'objective': 'regression',\n",
        "         'boosting': 'gbdt',\n",
        "         'num_iterations': 3000,   \n",
        "         'learning_rate': 0.06,  \n",
        "         'num_leaves': 40,  \n",
        "         'max_depth': 24,   \n",
        "         'min_data_in_leaf':11,  \n",
        "         'max_bin': 4, \n",
        "         'metric': 'l2_root'\n",
        "         }\n",
        "\n",
        "lgbm = lgb.train(params=param,\n",
        "                 verbose_eval=1000,\n",
        "                 train_set=train_data,\n",
        "                 valid_sets=[test_data])\n",
        "\n",
        "y_pred2 = lgbm.predict(X_cv)\n",
        "print('RMSLE:', sqrt(mean_squared_log_error(np.exp(y_cv), np.exp(y_pred2))))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[1000]\tvalid_0's rmse: 0.107172\n",
            "[2000]\tvalid_0's rmse: 0.105563\n",
            "[3000]\tvalid_0's rmse: 0.105689\n",
            "RMSLE: 0.10567509598337499\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "chwhL48euEZF",
        "colab_type": "code",
        "colab": {},
        "outputId": "513e99dc-6974-4657-f965-42011bf4e754"
      },
      "cell_type": "code",
      "source": [
        "from xgboost import XGBRegressor\n",
        "xgb = XGBRegressor(max_depth=9, \n",
        "                   learning_rate=0.5, \n",
        "                   n_estimators=112, \n",
        "                   silent=False, \n",
        "                   objective='reg:linear', \n",
        "                   booster='gbtree', \n",
        "                   n_jobs=1, \n",
        "                   nthread=None, \n",
        "                   gamma=0, \n",
        "                   min_child_weight=1, \n",
        "                   max_delta_step=0, \n",
        "                   subsample=1, \n",
        "                   colsample_bytree=1, \n",
        "                   colsample_bylevel=1, \n",
        "                   reg_alpha=1, \n",
        "                   reg_lambda=1, \n",
        "                   scale_pos_weight=1, \n",
        "                   base_score=0.5, \n",
        "                   random_state=0, \n",
        "                   seed=None)\n",
        "xgb.fit(X_train, y_train)\n",
        "y_pred1 = xgb.predict(X_cv)\n",
        "print('RMSLE:', sqrt(mean_squared_log_error(np.exp(y_cv), np.exp(y_pred1))))\n",
        "#RMSLE:0.11124007381703037"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "RMSLE: 0.11125264058400451\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "at8No8zzuEZJ",
        "colab_type": "code",
        "colab": {},
        "outputId": "d3bc5c58-9eee-4cff-8340-e8742651d167"
      },
      "cell_type": "code",
      "source": [
        "from sklearn.ensemble import BaggingRegressor\n",
        "br = BaggingRegressor(base_estimator=None, \n",
        "                      n_estimators=50, \n",
        "                      max_samples=1.0, \n",
        "                      max_features=1.0, \n",
        "                      bootstrap=True, \n",
        "                      bootstrap_features=False, \n",
        "                      oob_score=False, \n",
        "                      warm_start=False, \n",
        "                      n_jobs=1, \n",
        "                      random_state=1, \n",
        "                      verbose=0)\n",
        "br.fit(X_train, y_train)\n",
        "y_pred3 = br.predict(X_cv)\n",
        "print('RMSLE:', sqrt(mean_squared_log_error(np.exp(y_cv), np.exp(y_pred3))))\n",
        "#RMSLE:0.11265336177662688"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "RMSLE: 0.11278238526307509\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "PmMRE0RuuEZL",
        "colab_type": "code",
        "colab": {},
        "outputId": "4dabb181-1343-4285-c1fd-9edb2b87b58b"
      },
      "cell_type": "code",
      "source": [
        "from sklearn.ensemble import GradientBoostingRegressor\n",
        "gb = GradientBoostingRegressor(loss='ls', \n",
        "                               learning_rate=0.3, \n",
        "                               n_estimators=380, \n",
        "                               subsample=1.0, \n",
        "                               criterion='friedman_mse', \n",
        "                               min_samples_split=30, \n",
        "                               min_samples_leaf=1, \n",
        "                               min_weight_fraction_leaf=0.0, \n",
        "                               max_depth=7, \n",
        "                               min_impurity_decrease=0.0, \n",
        "                               min_impurity_split=None, \n",
        "                               init=None, \n",
        "                               random_state=0, \n",
        "                               max_features=None, \n",
        "                               alpha=0.9, \n",
        "                               verbose=100, \n",
        "                               max_leaf_nodes=None, \n",
        "                               warm_start=False, \n",
        "                               presort='auto')\n",
        "gb.fit(X_train, y_train)\n",
        "y_pred4 = gb.predict(X_cv)\n",
        "print('RMSLE:', sqrt(mean_squared_log_error(np.exp(y_cv), np.exp(y_pred4))))\n",
        "#RMSLE:0.11014737617371691"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "      Iter       Train Loss   Remaining Time \n",
            "         1           0.1420            4.18m\n",
            "         2           0.0829            3.82m\n",
            "         3           0.0515            4.03m\n",
            "         4           0.0356            3.96m\n",
            "         5           0.0270            3.91m\n",
            "         6           0.0225            4.00m\n",
            "         7           0.0195            3.92m\n",
            "         8           0.0177            3.85m\n",
            "         9           0.0163            3.81m\n",
            "        10           0.0155            3.73m\n",
            "        11           0.0146            3.63m\n",
            "        12           0.0141            3.49m\n",
            "        13           0.0137            3.37m\n",
            "        14           0.0133            3.28m\n",
            "        15           0.0129            3.18m\n",
            "        16           0.0127            3.08m\n",
            "        17           0.0125            2.98m\n",
            "        18           0.0124            2.87m\n",
            "        19           0.0122            2.77m\n",
            "        20           0.0117            2.81m\n",
            "        21           0.0116            2.76m\n",
            "        22           0.0112            2.77m\n",
            "        23           0.0111            2.71m\n",
            "        24           0.0111            2.65m\n",
            "        25           0.0110            2.60m\n",
            "        26           0.0109            2.55m\n",
            "        27           0.0107            2.51m\n",
            "        28           0.0106            2.47m\n",
            "        29           0.0105            2.46m\n",
            "        30           0.0104            2.44m\n",
            "        31           0.0103            2.41m\n",
            "        32           0.0103            2.36m\n",
            "        33           0.0100            2.34m\n",
            "        34           0.0100            2.31m\n",
            "        35           0.0099            2.30m\n",
            "        36           0.0097            2.29m\n",
            "        37           0.0097            2.25m\n",
            "        38           0.0096            2.22m\n",
            "        39           0.0096            2.20m\n",
            "        40           0.0095            2.17m\n",
            "        41           0.0094            2.15m\n",
            "        42           0.0093            2.13m\n",
            "        43           0.0093            2.12m\n",
            "        44           0.0092            2.10m\n",
            "        45           0.0092            2.08m\n",
            "        46           0.0091            2.05m\n",
            "        47           0.0090            2.04m\n",
            "        48           0.0090            2.02m\n",
            "        49           0.0089            2.02m\n",
            "        50           0.0089            2.00m\n",
            "        51           0.0088            1.98m\n",
            "        52           0.0087            1.96m\n",
            "        53           0.0086            1.95m\n",
            "        54           0.0085            1.95m\n",
            "        55           0.0084            1.94m\n",
            "        56           0.0083            1.92m\n",
            "        57           0.0082            1.90m\n",
            "        58           0.0082            1.88m\n",
            "        59           0.0081            1.86m\n",
            "        60           0.0081            1.84m\n",
            "        61           0.0081            1.83m\n",
            "        62           0.0080            1.82m\n",
            "        63           0.0080            1.80m\n",
            "        64           0.0080            1.79m\n",
            "        65           0.0079            1.79m\n",
            "        66           0.0079            1.78m\n",
            "        67           0.0078            1.77m\n",
            "        68           0.0078            1.76m\n",
            "        69           0.0078            1.74m\n",
            "        70           0.0078            1.73m\n",
            "        71           0.0077            1.71m\n",
            "        72           0.0077            1.70m\n",
            "        73           0.0077            1.69m\n",
            "        74           0.0077            1.67m\n",
            "        75           0.0077            1.66m\n",
            "        76           0.0075            1.67m\n",
            "        77           0.0075            1.66m\n",
            "        78           0.0075            1.65m\n",
            "        79           0.0074            1.65m\n",
            "        80           0.0073            1.64m\n",
            "        81           0.0073            1.63m\n",
            "        82           0.0072            1.63m\n",
            "        83           0.0072            1.62m\n",
            "        84           0.0072            1.61m\n",
            "        85           0.0071            1.60m\n",
            "        86           0.0071            1.59m\n",
            "        87           0.0071            1.58m\n",
            "        88           0.0071            1.57m\n",
            "        89           0.0071            1.56m\n",
            "        90           0.0071            1.55m\n",
            "        91           0.0070            1.54m\n",
            "        92           0.0070            1.53m\n",
            "        93           0.0070            1.53m\n",
            "        94           0.0069            1.53m\n",
            "        95           0.0069            1.52m\n",
            "        96           0.0068            1.51m\n",
            "        97           0.0068            1.51m\n",
            "        98           0.0068            1.50m\n",
            "        99           0.0068            1.49m\n",
            "       100           0.0067            1.48m\n",
            "       101           0.0067            1.47m\n",
            "       102           0.0067            1.46m\n",
            "       103           0.0067            1.45m\n",
            "       104           0.0066            1.45m\n",
            "       105           0.0066            1.44m\n",
            "       106           0.0066            1.43m\n",
            "       107           0.0065            1.42m\n",
            "       108           0.0065            1.43m\n",
            "       109           0.0065            1.42m\n",
            "       110           0.0064            1.42m\n",
            "       111           0.0064            1.41m\n",
            "       112           0.0064            1.40m\n",
            "       113           0.0064            1.39m\n",
            "       114           0.0064            1.38m\n",
            "       115           0.0063            1.38m\n",
            "       116           0.0063            1.37m\n",
            "       117           0.0063            1.36m\n",
            "       118           0.0063            1.36m\n",
            "       119           0.0063            1.35m\n",
            "       120           0.0063            1.35m\n",
            "       121           0.0063            1.34m\n",
            "       122           0.0062            1.33m\n",
            "       123           0.0062            1.33m\n",
            "       124           0.0062            1.33m\n",
            "       125           0.0062            1.32m\n",
            "       126           0.0062            1.31m\n",
            "       127           0.0062            1.31m\n",
            "       128           0.0061            1.30m\n",
            "       129           0.0061            1.29m\n",
            "       130           0.0061            1.28m\n",
            "       131           0.0061            1.28m\n",
            "       132           0.0061            1.27m\n",
            "       133           0.0061            1.26m\n",
            "       134           0.0060            1.25m\n",
            "       135           0.0060            1.25m\n",
            "       136           0.0060            1.24m\n",
            "       137           0.0059            1.23m\n",
            "       138           0.0058            1.23m\n",
            "       139           0.0058            1.22m\n",
            "       140           0.0058            1.21m\n",
            "       141           0.0058            1.20m\n",
            "       142           0.0058            1.20m\n",
            "       143           0.0058            1.19m\n",
            "       144           0.0057            1.19m\n",
            "       145           0.0057            1.18m\n",
            "       146           0.0057            1.18m\n",
            "       147           0.0057            1.17m\n",
            "       148           0.0056            1.17m\n",
            "       149           0.0056            1.16m\n",
            "       150           0.0056            1.15m\n",
            "       151           0.0056            1.15m\n",
            "       152           0.0056            1.14m\n",
            "       153           0.0055            1.13m\n",
            "       154           0.0055            1.13m\n",
            "       155           0.0055            1.12m\n",
            "       156           0.0055            1.11m\n",
            "       157           0.0055            1.11m\n",
            "       158           0.0055            1.10m\n",
            "       159           0.0055            1.10m\n",
            "       160           0.0055            1.09m\n",
            "       161           0.0055            1.09m\n",
            "       162           0.0054            1.08m\n",
            "       163           0.0054            1.07m\n",
            "       164           0.0054            1.07m\n",
            "       165           0.0054            1.06m\n",
            "       166           0.0054            1.05m\n",
            "       167           0.0054            1.05m\n",
            "       168           0.0054            1.04m\n",
            "       169           0.0054            1.04m\n",
            "       170           0.0053            1.04m\n",
            "       171           0.0053            1.03m\n",
            "       172           0.0053            1.02m\n",
            "       173           0.0053            1.02m\n",
            "       174           0.0053            1.01m\n",
            "       175           0.0052            1.01m\n",
            "       176           0.0052            1.00m\n",
            "       177           0.0052           59.80s\n",
            "       178           0.0052           59.50s\n",
            "       179           0.0052           59.34s\n",
            "       180           0.0052           59.05s\n",
            "       181           0.0052           58.87s\n",
            "       182           0.0052           58.57s\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "stream",
          "text": [
            "       183           0.0052           58.23s\n",
            "       184           0.0051           57.90s\n",
            "       185           0.0051           57.57s\n",
            "       186           0.0051           57.23s\n",
            "       187           0.0051           56.85s\n",
            "       188           0.0051           56.47s\n",
            "       189           0.0051           56.10s\n",
            "       190           0.0051           55.77s\n",
            "       191           0.0051           55.53s\n",
            "       192           0.0050           55.20s\n",
            "       193           0.0050           55.06s\n",
            "       194           0.0050           54.89s\n",
            "       195           0.0050           54.57s\n",
            "       196           0.0050           54.18s\n",
            "       197           0.0050           53.80s\n",
            "       198           0.0049           53.53s\n",
            "       199           0.0049           53.21s\n",
            "       200           0.0049           52.91s\n",
            "       201           0.0049           52.66s\n",
            "       202           0.0049           52.58s\n",
            "       203           0.0049           52.21s\n",
            "       204           0.0049           51.83s\n",
            "       205           0.0048           51.49s\n",
            "       206           0.0048           51.40s\n",
            "       207           0.0048           51.17s\n",
            "       208           0.0047           51.10s\n",
            "       209           0.0047           50.98s\n",
            "       210           0.0047           50.66s\n",
            "       211           0.0047           50.52s\n",
            "       212           0.0046           50.16s\n",
            "       213           0.0046           49.76s\n",
            "       214           0.0046           49.38s\n",
            "       215           0.0046           49.17s\n",
            "       216           0.0046           48.98s\n",
            "       217           0.0046           48.62s\n",
            "       218           0.0046           48.27s\n",
            "       219           0.0046           47.93s\n",
            "       220           0.0046           47.55s\n",
            "       221           0.0045           47.24s\n",
            "       222           0.0045           46.94s\n",
            "       223           0.0045           46.61s\n",
            "       224           0.0045           46.27s\n",
            "       225           0.0045           45.96s\n",
            "       226           0.0045           45.70s\n",
            "       227           0.0045           45.59s\n",
            "       228           0.0044           45.34s\n",
            "       229           0.0044           45.01s\n",
            "       230           0.0044           44.73s\n",
            "       231           0.0044           44.45s\n",
            "       232           0.0044           44.13s\n",
            "       233           0.0044           43.84s\n",
            "       234           0.0044           43.48s\n",
            "       235           0.0044           43.20s\n",
            "       236           0.0044           42.96s\n",
            "       237           0.0044           42.64s\n",
            "       238           0.0043           42.29s\n",
            "       239           0.0043           41.92s\n",
            "       240           0.0043           41.58s\n",
            "       241           0.0043           41.23s\n",
            "       242           0.0043           40.92s\n",
            "       243           0.0043           40.59s\n",
            "       244           0.0043           40.28s\n",
            "       245           0.0043           39.95s\n",
            "       246           0.0043           39.65s\n",
            "       247           0.0043           39.32s\n",
            "       248           0.0043           39.02s\n",
            "       249           0.0043           38.72s\n",
            "       250           0.0043           38.40s\n",
            "       251           0.0042           38.10s\n",
            "       252           0.0042           37.82s\n",
            "       253           0.0042           37.53s\n",
            "       254           0.0042           37.19s\n",
            "       255           0.0042           36.89s\n",
            "       256           0.0042           36.61s\n",
            "       257           0.0042           36.37s\n",
            "       258           0.0042           36.04s\n",
            "       259           0.0042           35.70s\n",
            "       260           0.0042           35.40s\n",
            "       261           0.0042           35.14s\n",
            "       262           0.0041           34.93s\n",
            "       263           0.0041           34.63s\n",
            "       264           0.0041           34.42s\n",
            "       265           0.0041           34.09s\n",
            "       266           0.0041           33.84s\n",
            "       267           0.0040           33.63s\n",
            "       268           0.0040           33.36s\n",
            "       269           0.0040           33.14s\n",
            "       270           0.0040           32.80s\n",
            "       271           0.0040           32.48s\n",
            "       272           0.0039           32.22s\n",
            "       273           0.0039           32.01s\n",
            "       274           0.0039           31.74s\n",
            "       275           0.0039           31.45s\n",
            "       276           0.0039           31.13s\n",
            "       277           0.0039           30.81s\n",
            "       278           0.0039           30.49s\n",
            "       279           0.0039           30.20s\n",
            "       280           0.0039           29.90s\n",
            "       281           0.0039           29.60s\n",
            "       282           0.0039           29.30s\n",
            "       283           0.0038           29.10s\n",
            "       284           0.0038           28.87s\n",
            "       285           0.0038           28.55s\n",
            "       286           0.0038           28.24s\n",
            "       287           0.0038           27.95s\n",
            "       288           0.0037           27.64s\n",
            "       289           0.0037           27.32s\n",
            "       290           0.0037           27.01s\n",
            "       291           0.0037           26.78s\n",
            "       292           0.0037           26.45s\n",
            "       293           0.0037           26.13s\n",
            "       294           0.0037           25.83s\n",
            "       295           0.0037           25.50s\n",
            "       296           0.0037           25.21s\n",
            "       297           0.0037           24.91s\n",
            "       298           0.0037           24.60s\n",
            "       299           0.0037           24.38s\n",
            "       300           0.0037           24.08s\n",
            "       301           0.0036           23.77s\n",
            "       302           0.0036           23.47s\n",
            "       303           0.0036           23.17s\n",
            "       304           0.0036           22.89s\n",
            "       305           0.0036           22.62s\n",
            "       306           0.0036           22.40s\n",
            "       307           0.0035           22.09s\n",
            "       308           0.0035           21.77s\n",
            "       309           0.0035           21.45s\n",
            "       310           0.0035           21.17s\n",
            "       311           0.0035           20.96s\n",
            "       312           0.0035           20.64s\n",
            "       313           0.0035           20.32s\n",
            "       314           0.0034           20.03s\n",
            "       315           0.0034           19.74s\n",
            "       316           0.0034           19.43s\n",
            "       317           0.0034           19.19s\n",
            "       318           0.0034           18.89s\n",
            "       319           0.0034           18.60s\n",
            "       320           0.0034           18.29s\n",
            "       321           0.0034           17.99s\n",
            "       322           0.0034           17.68s\n",
            "       323           0.0034           17.37s\n",
            "       324           0.0034           17.07s\n",
            "       325           0.0034           16.76s\n",
            "       326           0.0034           16.46s\n",
            "       327           0.0034           16.15s\n",
            "       328           0.0033           15.83s\n",
            "       329           0.0033           15.51s\n",
            "       330           0.0033           15.20s\n",
            "       331           0.0033           14.91s\n",
            "       332           0.0033           14.60s\n",
            "       333           0.0033           14.28s\n",
            "       334           0.0033           13.99s\n",
            "       335           0.0033           13.68s\n",
            "       336           0.0033           13.39s\n",
            "       337           0.0033           13.08s\n",
            "       338           0.0033           12.77s\n",
            "       339           0.0033           12.46s\n",
            "       340           0.0033           12.15s\n",
            "       341           0.0033           11.83s\n",
            "       342           0.0033           11.52s\n",
            "       343           0.0033           11.22s\n",
            "       344           0.0033           10.90s\n",
            "       345           0.0033           10.60s\n",
            "       346           0.0033           10.29s\n",
            "       347           0.0033            9.98s\n",
            "       348           0.0033            9.68s\n",
            "       349           0.0032            9.37s\n",
            "       350           0.0032            9.08s\n",
            "       351           0.0032            8.77s\n",
            "       352           0.0032            8.46s\n",
            "       353           0.0032            8.16s\n",
            "       354           0.0032            7.86s\n",
            "       355           0.0032            7.55s\n",
            "       356           0.0032            7.25s\n",
            "       357           0.0032            6.94s\n",
            "       358           0.0032            6.65s\n",
            "       359           0.0032            6.34s\n",
            "       360           0.0032            6.04s\n",
            "       361           0.0032            5.74s\n",
            "       362           0.0032            5.43s\n",
            "       363           0.0032            5.13s\n",
            "       364           0.0032            4.83s\n",
            "       365           0.0032            4.53s\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "stream",
          "text": [
            "       366           0.0032            4.24s\n",
            "       367           0.0032            3.94s\n",
            "       368           0.0031            3.64s\n",
            "       369           0.0031            3.34s\n",
            "       370           0.0031            3.03s\n",
            "       371           0.0031            2.73s\n",
            "       372           0.0031            2.43s\n",
            "       373           0.0031            2.12s\n",
            "       374           0.0031            1.82s\n",
            "       375           0.0031            1.52s\n",
            "       376           0.0031            1.21s\n",
            "       377           0.0031            0.91s\n",
            "       378           0.0031            0.61s\n",
            "       379           0.0031            0.30s\n",
            "       380           0.0031            0.00s\n",
            "RMSLE: 0.10977714681935279\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "F1kblbJguEZQ",
        "colab_type": "code",
        "colab": {},
        "outputId": "dac78922-e37a-48cf-edfa-5ee80e49b571"
      },
      "cell_type": "code",
      "source": [
        "y_pred = y_pred1*0.10 + y_pred2*0.50 + y_pred3*0.20 + y_pred4*0.20\n",
        "print('RMSLE:', sqrt(mean_squared_log_error(np.exp(y_cv), np.exp(y_pred))))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "RMSLE: 0.1013472363709534\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "7LxhKNJ8uEZV",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## Predict on test set"
      ]
    },
    {
      "metadata": {
        "id": "Mkk0x-kuuEZW",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df['Dep_Time_22:30'] = 0"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "DMKrX3KYuEZZ",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "missing_cols_test = []\n",
        "for col in train_df.columns:\n",
        "    if col not in test_df.columns:\n",
        "        missing_cols_test.append(col)\n",
        "        \n",
        "for i in missing_cols_test:\n",
        "    test_df[i] = 0\n",
        "\n",
        "test_df.drop('Price', axis=1, inplace=True)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "nv2VfSEwuEZb",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_df = train_df.reindex(sorted(train_df.columns), axis=1)\n",
        "test_df = test_df.reindex(sorted(test_df.columns), axis=1)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "Uv2UhZ2KuEZf",
        "colab_type": "code",
        "colab": {},
        "outputId": "aa926f2c-9b96-4afa-b143-6483d6a7fa28"
      },
      "cell_type": "code",
      "source": [
        "train_df.shape, test_df.shape"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "((10683, 571), (2671, 570))"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 198
        }
      ]
    },
    {
      "metadata": {
        "id": "FqZpqNLzuEZn",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "X_train = train_df.drop(labels='Price', axis=1)\n",
        "y_train = train_df['Price'].values\n",
        "\n",
        "X_test = test_df"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "YaWrCd6uuEZq",
        "colab_type": "code",
        "colab": {},
        "outputId": "1ebf1583-0113-424d-be12-58a6d8c04656"
      },
      "cell_type": "code",
      "source": [
        "X_train.shape, X_test.shape"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "((10683, 570), (2671, 570))"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 200
        }
      ]
    },
    {
      "metadata": {
        "id": "TxjYRB_5uEZv",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "from xgboost import XGBRegressor\n",
        "xgb = XGBRegressor(max_depth=9, \n",
        "                   learning_rate=0.5, \n",
        "                   n_estimators=112, \n",
        "                   silent=False, \n",
        "                   objective='reg:linear', \n",
        "                   booster='gbtree', \n",
        "                   n_jobs=1, \n",
        "                   nthread=None, \n",
        "                   gamma=0, \n",
        "                   min_child_weight=1, \n",
        "                   max_delta_step=0, \n",
        "                   subsample=1, \n",
        "                   colsample_bytree=1, \n",
        "                   colsample_bylevel=1, \n",
        "                   reg_alpha=0.89, \n",
        "                   reg_lambda=1, \n",
        "                   scale_pos_weight=1, \n",
        "                   base_score=0.5, \n",
        "                   random_state=0, \n",
        "                   seed=None)\n",
        "xgb.fit(X_train, y_train)\n",
        "y_pred1 = xgb.predict(X_test)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "qsMW6w3zuEZz",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "import lightgbm as lgb\n",
        "train_data = lgb.Dataset(X_train, label=y_train)\n",
        "\n",
        "param = {'objective': 'regression',\n",
        "         'boosting': 'gbdt',\n",
        "         'num_iterations': 3000,   \n",
        "         'learning_rate': 0.06,  \n",
        "         'num_leaves': 40,  \n",
        "         'max_depth': 24,   \n",
        "         'min_data_in_leaf':11,  \n",
        "         'max_bin': 4, \n",
        "         'metric': 'l2_root'\n",
        "         }\n",
        "\n",
        "lgbm = lgb.train(params=param,\n",
        "                 train_set=train_data)\n",
        "\n",
        "y_pred2 = lgbm.predict(X_test)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "fMmrR3VsuEZ4",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "from sklearn.ensemble import BaggingRegressor\n",
        "br = BaggingRegressor(base_estimator=None, \n",
        "                      n_estimators=50, \n",
        "                      max_samples=1.0, \n",
        "                      max_features=1.0, \n",
        "                      bootstrap=True, \n",
        "                      bootstrap_features=False, \n",
        "                      oob_score=False, \n",
        "                      warm_start=False, \n",
        "                      n_jobs=1, \n",
        "                      random_state=1, \n",
        "                      verbose=0)\n",
        "br.fit(X_train, y_train)\n",
        "y_pred3 = br.predict(X_test)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "VTR7s0eVuEZ5",
        "colab_type": "code",
        "colab": {},
        "outputId": "c9ebbef6-5f01-43a1-9f0c-f9ac6db65c8d"
      },
      "cell_type": "code",
      "source": [
        "from sklearn.ensemble import GradientBoostingRegressor\n",
        "gb = GradientBoostingRegressor(loss='ls', \n",
        "                               learning_rate=0.3, \n",
        "                               n_estimators=380, \n",
        "                               subsample=1.0, \n",
        "                               criterion='friedman_mse', \n",
        "                               min_samples_split=30, \n",
        "                               min_samples_leaf=1, \n",
        "                               min_weight_fraction_leaf=0.0, \n",
        "                               max_depth=7, \n",
        "                               min_impurity_decrease=0.0, \n",
        "                               min_impurity_split=None, \n",
        "                               init=None, \n",
        "                               random_state=0, \n",
        "                               max_features=None, \n",
        "                               alpha=0.9, \n",
        "                               verbose=100, \n",
        "                               max_leaf_nodes=None, \n",
        "                               warm_start=False, \n",
        "                               presort='auto')\n",
        "gb.fit(X_train, y_train)\n",
        "y_pred4 = gb.predict(X_test)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "      Iter       Train Loss   Remaining Time \n",
            "         1           0.1429            4.23m\n",
            "         2           0.0829            4.17m\n",
            "         3           0.0526            4.09m\n",
            "         4           0.0367            4.03m\n",
            "         5           0.0281            3.99m\n",
            "         6           0.0228            3.95m\n",
            "         7           0.0199            3.97m\n",
            "         8           0.0178            3.89m\n",
            "         9           0.0167            3.92m\n",
            "        10           0.0159            3.86m\n",
            "        11           0.0153            3.79m\n",
            "        12           0.0145            3.74m\n",
            "        13           0.0140            3.69m\n",
            "        14           0.0137            3.60m\n",
            "        15           0.0133            3.52m\n",
            "        16           0.0131            3.44m\n",
            "        17           0.0128            3.43m\n",
            "        18           0.0127            3.36m\n",
            "        19           0.0126            3.31m\n",
            "        20           0.0124            3.33m\n",
            "        21           0.0122            3.34m\n",
            "        22           0.0121            3.29m\n",
            "        23           0.0120            3.24m\n",
            "        24           0.0117            3.21m\n",
            "        25           0.0116            3.22m\n",
            "        26           0.0114            3.19m\n",
            "        27           0.0113            3.16m\n",
            "        28           0.0111            3.17m\n",
            "        29           0.0111            3.12m\n",
            "        30           0.0110            3.06m\n",
            "        31           0.0109            3.00m\n",
            "        32           0.0109            2.96m\n",
            "        33           0.0108            2.95m\n",
            "        34           0.0107            2.91m\n",
            "        35           0.0107            2.87m\n",
            "        36           0.0105            2.88m\n",
            "        37           0.0104            2.86m\n",
            "        38           0.0103            2.83m\n",
            "        39           0.0101            2.87m\n",
            "        40           0.0100            2.85m\n",
            "        41           0.0100            2.85m\n",
            "        42           0.0099            2.83m\n",
            "        43           0.0097            2.84m\n",
            "        44           0.0096            2.82m\n",
            "        45           0.0096            2.80m\n",
            "        46           0.0095            2.78m\n",
            "        47           0.0094            2.76m\n",
            "        48           0.0094            2.76m\n",
            "        49           0.0093            2.74m\n",
            "        50           0.0093            2.71m\n",
            "        51           0.0091            2.69m\n",
            "        52           0.0091            2.66m\n",
            "        53           0.0089            2.66m\n",
            "        54           0.0089            2.63m\n",
            "        55           0.0089            2.60m\n",
            "        56           0.0088            2.59m\n",
            "        57           0.0088            2.55m\n",
            "        58           0.0087            2.52m\n",
            "        59           0.0086            2.50m\n",
            "        60           0.0086            2.47m\n",
            "        61           0.0085            2.46m\n",
            "        62           0.0085            2.43m\n",
            "        63           0.0084            2.41m\n",
            "        64           0.0084            2.39m\n",
            "        65           0.0084            2.37m\n",
            "        66           0.0083            2.35m\n",
            "        67           0.0083            2.33m\n",
            "        68           0.0083            2.32m\n",
            "        69           0.0082            2.30m\n",
            "        70           0.0082            2.28m\n",
            "        71           0.0082            2.26m\n",
            "        72           0.0082            2.25m\n",
            "        73           0.0081            2.23m\n",
            "        74           0.0081            2.21m\n",
            "        75           0.0081            2.20m\n",
            "        76           0.0080            2.18m\n",
            "        77           0.0080            2.17m\n",
            "        78           0.0080            2.16m\n",
            "        79           0.0080            2.14m\n",
            "        80           0.0079            2.12m\n",
            "        81           0.0077            2.13m\n",
            "        82           0.0076            2.14m\n",
            "        83           0.0075            2.15m\n",
            "        84           0.0075            2.14m\n",
            "        85           0.0074            2.12m\n",
            "        86           0.0074            2.11m\n",
            "        87           0.0074            2.10m\n",
            "        88           0.0073            2.09m\n",
            "        89           0.0073            2.08m\n",
            "        90           0.0073            2.06m\n",
            "        91           0.0073            2.05m\n",
            "        92           0.0072            2.05m\n",
            "        93           0.0072            2.05m\n",
            "        94           0.0072            2.04m\n",
            "        95           0.0071            2.04m\n",
            "        96           0.0070            2.02m\n",
            "        97           0.0070            2.01m\n",
            "        98           0.0070            2.00m\n",
            "        99           0.0070            2.00m\n",
            "       100           0.0069            1.99m\n",
            "       101           0.0069            1.98m\n",
            "       102           0.0069            1.97m\n",
            "       103           0.0069            1.96m\n",
            "       104           0.0069            1.95m\n",
            "       105           0.0068            1.95m\n",
            "       106           0.0068            1.94m\n",
            "       107           0.0067            1.94m\n",
            "       108           0.0067            1.96m\n",
            "       109           0.0066            1.95m\n",
            "       110           0.0066            1.94m\n",
            "       111           0.0066            1.93m\n",
            "       112           0.0066            1.91m\n",
            "       113           0.0065            1.90m\n",
            "       114           0.0065            1.89m\n",
            "       115           0.0065            1.88m\n",
            "       116           0.0065            1.87m\n",
            "       117           0.0065            1.86m\n",
            "       118           0.0065            1.85m\n",
            "       119           0.0065            1.85m\n",
            "       120           0.0064            1.84m\n",
            "       121           0.0064            1.83m\n",
            "       122           0.0064            1.82m\n",
            "       123           0.0064            1.81m\n",
            "       124           0.0064            1.81m\n",
            "       125           0.0063            1.80m\n",
            "       126           0.0063            1.79m\n",
            "       127           0.0063            1.78m\n",
            "       128           0.0063            1.78m\n",
            "       129           0.0063            1.77m\n",
            "       130           0.0063            1.76m\n",
            "       131           0.0063            1.75m\n",
            "       132           0.0063            1.75m\n",
            "       133           0.0062            1.74m\n",
            "       134           0.0062            1.74m\n",
            "       135           0.0062            1.72m\n",
            "       136           0.0061            1.71m\n",
            "       137           0.0061            1.70m\n",
            "       138           0.0061            1.69m\n",
            "       139           0.0061            1.69m\n",
            "       140           0.0060            1.68m\n",
            "       141           0.0060            1.68m\n",
            "       142           0.0060            1.67m\n",
            "       143           0.0060            1.68m\n",
            "       144           0.0059            1.67m\n",
            "       145           0.0059            1.67m\n",
            "       146           0.0059            1.66m\n",
            "       147           0.0059            1.65m\n",
            "       148           0.0059            1.65m\n",
            "       149           0.0059            1.64m\n",
            "       150           0.0058            1.63m\n",
            "       151           0.0058            1.62m\n",
            "       152           0.0058            1.61m\n",
            "       153           0.0058            1.60m\n",
            "       154           0.0058            1.59m\n",
            "       155           0.0058            1.58m\n",
            "       156           0.0058            1.57m\n",
            "       157           0.0058            1.56m\n",
            "       158           0.0058            1.55m\n",
            "       159           0.0058            1.54m\n",
            "       160           0.0058            1.53m\n",
            "       161           0.0058            1.53m\n",
            "       162           0.0058            1.52m\n",
            "       163           0.0057            1.51m\n",
            "       164           0.0057            1.51m\n",
            "       165           0.0057            1.50m\n",
            "       166           0.0057            1.50m\n",
            "       167           0.0056            1.49m\n",
            "       168           0.0056            1.48m\n",
            "       169           0.0056            1.48m\n",
            "       170           0.0056            1.47m\n",
            "       171           0.0056            1.46m\n",
            "       172           0.0056            1.45m\n",
            "       173           0.0056            1.45m\n",
            "       174           0.0056            1.44m\n",
            "       175           0.0056            1.43m\n",
            "       176           0.0056            1.43m\n",
            "       177           0.0055            1.42m\n",
            "       178           0.0055            1.41m\n",
            "       179           0.0055            1.41m\n",
            "       180           0.0055            1.40m\n",
            "       181           0.0055            1.39m\n",
            "       182           0.0054            1.38m\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "stream",
          "text": [
            "       183           0.0054            1.37m\n",
            "       184           0.0054            1.37m\n",
            "       185           0.0054            1.36m\n",
            "       186           0.0053            1.36m\n",
            "       187           0.0053            1.35m\n",
            "       188           0.0052            1.34m\n",
            "       189           0.0052            1.34m\n",
            "       190           0.0052            1.33m\n",
            "       191           0.0051            1.32m\n",
            "       192           0.0051            1.31m\n",
            "       193           0.0051            1.31m\n",
            "       194           0.0051            1.30m\n",
            "       195           0.0051            1.29m\n",
            "       196           0.0051            1.29m\n",
            "       197           0.0051            1.28m\n",
            "       198           0.0050            1.27m\n",
            "       199           0.0050            1.26m\n",
            "       200           0.0050            1.25m\n",
            "       201           0.0050            1.25m\n",
            "       202           0.0050            1.24m\n",
            "       203           0.0050            1.23m\n",
            "       204           0.0050            1.22m\n",
            "       205           0.0049            1.22m\n",
            "       206           0.0049            1.21m\n",
            "       207           0.0049            1.20m\n",
            "       208           0.0049            1.20m\n",
            "       209           0.0049            1.19m\n",
            "       210           0.0049            1.18m\n",
            "       211           0.0048            1.17m\n",
            "       212           0.0048            1.16m\n",
            "       213           0.0048            1.15m\n",
            "       214           0.0048            1.15m\n",
            "       215           0.0048            1.14m\n",
            "       216           0.0048            1.13m\n",
            "       217           0.0048            1.13m\n",
            "       218           0.0048            1.12m\n",
            "       219           0.0048            1.12m\n",
            "       220           0.0048            1.11m\n",
            "       221           0.0047            1.11m\n",
            "       222           0.0047            1.10m\n",
            "       223           0.0047            1.10m\n",
            "       224           0.0046            1.09m\n",
            "       225           0.0046            1.09m\n",
            "       226           0.0046            1.08m\n",
            "       227           0.0046            1.07m\n",
            "       228           0.0045            1.06m\n",
            "       229           0.0045            1.06m\n",
            "       230           0.0045            1.05m\n",
            "       231           0.0045            1.05m\n",
            "       232           0.0045            1.04m\n",
            "       233           0.0045            1.03m\n",
            "       234           0.0044            1.03m\n",
            "       235           0.0044            1.02m\n",
            "       236           0.0044            1.01m\n",
            "       237           0.0044            1.01m\n",
            "       238           0.0044           59.83s\n",
            "       239           0.0044           59.34s\n",
            "       240           0.0044           58.95s\n",
            "       241           0.0044           58.63s\n",
            "       242           0.0044           58.22s\n",
            "       243           0.0044           57.73s\n",
            "       244           0.0044           57.34s\n",
            "       245           0.0043           56.99s\n",
            "       246           0.0043           56.53s\n",
            "       247           0.0043           56.08s\n",
            "       248           0.0043           55.71s\n",
            "       249           0.0043           55.29s\n",
            "       250           0.0043           54.80s\n",
            "       251           0.0043           54.37s\n",
            "       252           0.0043           53.88s\n",
            "       253           0.0043           53.55s\n",
            "       254           0.0042           53.17s\n",
            "       255           0.0042           52.73s\n",
            "       256           0.0042           52.27s\n",
            "       257           0.0042           51.91s\n",
            "       258           0.0042           51.67s\n",
            "       259           0.0042           51.21s\n",
            "       260           0.0041           50.88s\n",
            "       261           0.0041           50.39s\n",
            "       262           0.0041           49.95s\n",
            "       263           0.0041           49.47s\n",
            "       264           0.0041           49.14s\n",
            "       265           0.0041           48.67s\n",
            "       266           0.0041           48.27s\n",
            "       267           0.0041           47.85s\n",
            "       268           0.0041           47.53s\n",
            "       269           0.0041           47.10s\n",
            "       270           0.0041           46.66s\n",
            "       271           0.0041           46.19s\n",
            "       272           0.0041           45.80s\n",
            "       273           0.0040           45.47s\n",
            "       274           0.0040           45.07s\n",
            "       275           0.0040           44.73s\n",
            "       276           0.0040           44.32s\n",
            "       277           0.0040           43.88s\n",
            "       278           0.0040           43.43s\n",
            "       279           0.0040           43.00s\n",
            "       280           0.0040           42.55s\n",
            "       281           0.0040           42.16s\n",
            "       282           0.0040           41.71s\n",
            "       283           0.0039           41.37s\n",
            "       284           0.0039           40.91s\n",
            "       285           0.0039           40.51s\n",
            "       286           0.0039           40.08s\n",
            "       287           0.0039           39.68s\n",
            "       288           0.0039           39.26s\n",
            "       289           0.0039           38.83s\n",
            "       290           0.0039           38.53s\n",
            "       291           0.0039           38.07s\n",
            "       292           0.0039           37.66s\n",
            "       293           0.0039           37.22s\n",
            "       294           0.0039           36.80s\n",
            "       295           0.0039           36.34s\n",
            "       296           0.0039           35.87s\n",
            "       297           0.0038           35.41s\n",
            "       298           0.0038           34.95s\n",
            "       299           0.0038           34.49s\n",
            "       300           0.0038           34.03s\n",
            "       301           0.0038           33.57s\n",
            "       302           0.0038           33.16s\n",
            "       303           0.0038           32.77s\n",
            "       304           0.0038           32.37s\n",
            "       305           0.0038           31.93s\n",
            "       306           0.0038           31.61s\n",
            "       307           0.0038           31.17s\n",
            "       308           0.0037           30.73s\n",
            "       309           0.0037           30.29s\n",
            "       310           0.0037           29.86s\n",
            "       311           0.0037           29.43s\n",
            "       312           0.0037           28.98s\n",
            "       313           0.0037           28.54s\n",
            "       314           0.0037           28.14s\n",
            "       315           0.0037           27.78s\n",
            "       316           0.0037           27.49s\n",
            "       317           0.0037           27.10s\n",
            "       318           0.0037           26.66s\n",
            "       319           0.0037           26.27s\n",
            "       320           0.0037           25.83s\n",
            "       321           0.0037           25.48s\n",
            "       322           0.0036           25.12s\n",
            "       323           0.0036           24.70s\n",
            "       324           0.0036           24.32s\n",
            "       325           0.0036           23.89s\n",
            "       326           0.0036           23.45s\n",
            "       327           0.0036           23.00s\n",
            "       328           0.0036           22.56s\n",
            "       329           0.0036           22.16s\n",
            "       330           0.0035           21.71s\n",
            "       331           0.0035           21.28s\n",
            "       332           0.0035           20.83s\n",
            "       333           0.0035           20.38s\n",
            "       334           0.0035           20.00s\n",
            "       335           0.0035           19.56s\n",
            "       336           0.0035           19.14s\n",
            "       337           0.0035           18.71s\n",
            "       338           0.0035           18.29s\n",
            "       339           0.0035           17.83s\n",
            "       340           0.0035           17.40s\n",
            "       341           0.0035           16.95s\n",
            "       342           0.0035           16.51s\n",
            "       343           0.0035           16.06s\n",
            "       344           0.0035           15.64s\n",
            "       345           0.0035           15.23s\n",
            "       346           0.0034           14.82s\n",
            "       347           0.0034           14.37s\n",
            "       348           0.0034           13.93s\n",
            "       349           0.0034           13.49s\n",
            "       350           0.0034           13.04s\n",
            "       351           0.0034           12.60s\n",
            "       352           0.0034           12.16s\n",
            "       353           0.0034           11.72s\n",
            "       354           0.0034           11.28s\n",
            "       355           0.0034           10.84s\n",
            "       356           0.0034           10.41s\n",
            "       357           0.0034            9.97s\n",
            "       358           0.0034            9.53s\n",
            "       359           0.0034            9.09s\n",
            "       360           0.0034            8.65s\n",
            "       361           0.0034            8.22s\n",
            "       362           0.0034            7.78s\n",
            "       363           0.0034            7.34s\n",
            "       364           0.0034            6.91s\n",
            "       365           0.0034            6.47s\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "stream",
          "text": [
            "       366           0.0034            6.04s\n",
            "       367           0.0034            5.60s\n",
            "       368           0.0034            5.18s\n",
            "       369           0.0034            4.74s\n",
            "       370           0.0034            4.31s\n",
            "       371           0.0034            3.88s\n",
            "       372           0.0033            3.44s\n",
            "       373           0.0033            3.01s\n",
            "       374           0.0033            2.59s\n",
            "       375           0.0033            2.16s\n",
            "       376           0.0033            1.73s\n",
            "       377           0.0033            1.30s\n",
            "       378           0.0033            0.86s\n",
            "       379           0.0033            0.43s\n",
            "       380           0.0033            0.00s\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "v3c5fVesuEZ8",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "y_pred = y_pred1*0.15 + y_pred2*0.50 + y_pred3*0.15 + y_pred4*0.20"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "qwp4cRFjuEaA",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "y_pred = np.exp(y_pred)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "aIY0cD9cuEaD",
        "colab_type": "code",
        "colab": {},
        "outputId": "777ba88a-1088-4923-a332-c8dffad3ca38"
      },
      "cell_type": "code",
      "source": [
        "y_pred[:5]"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([14406.06843791,  4209.53341524, 12895.31525683, 11535.5327643 ,\n",
              "        3943.37074688])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 207
        }
      ]
    },
    {
      "metadata": {
        "id": "X7V5cRdFuEaH",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "df_sub = pd.DataFrame(data=y_pred, columns=['Price'])\n",
        "writer = pd.ExcelWriter('Output.xlsx', engine='xlsxwriter')\n",
        "df_sub.to_excel(writer,sheet_name='Sheet1', index=False)\n",
        "writer.save()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "_7NDxIbCuEaJ",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}
